define(function (require) {
    require('share');
    var utils = require('utils');
    var obj = {
        init: function () {
            this.getData()
        },
        getData: function () {
            var index = utils.tipsLoading("数据加载中");
            var rest = $.restPost('boxGroup/list', {
                userId: JSON.parse(utils.getLocalStorage('userinfo')).id
            });
            rest.done(function (msg, data) {
                utils.tipsClose(index);
                $("#group-tmpl").html(utils.tmpl("tmpl", {objs: data}));
            });
            rest.fail(function (msg) {
                utils.tipsClose(index);
                utils.tipsError(msg);
            });
        },
        goToDetail: function () {
            utils.goTo('cabinet-list.html?id=' + $(this).data('id'));
        },
        logout: function () {
            utils.tipsSingleSelect('确认退出？', ['退出', '关闭'], function () {
                utils.delLocalStorage('userinfo')
                utils.goTo('login.html')
            })
        }
    };

    $(function () {
        obj.init();
        $('#group-tmpl').on('click', '.group-item', obj.goToDetail)
        $('#logout').click(obj.logout)
        $('#refresh').click(obj.getData)
    })

});